package com.unibuy.smartdevice.ui;

import android.content.Context;
import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.unibuy.smartdevice.AppCompatActivityAbstract;
import com.unibuy.smartdevice.MyApp;
import com.unibuy.smartdevice.database.MemoDao;
import com.unibuy.smartdevice.database.SettingsDao;
import com.unibuy.smartdevice.databinding.ActivitySettingTestBinding;
import com.unibuy.smartdevice.databinding.ActivitySystemSetBinding;
import com.unibuy.smartdevice.structure.DevSetStructure;
import com.unibuy.smartdevice.structure.MemoStructure;
import com.unibuy.smartdevice.tools.HandlerMain;
import com.unibuy.smartdevice.tools.ToastHandlerMain;
import com.unibuy.smartdevice.tools.Tools;
import com.unibuy.smartdevice.ui.recycler.RecyclerSettingListAdpter;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class SystemSetActivity extends AppCompatActivityAbstract {
    private ActivitySystemSetBinding binding;

    @Override
    protected Context setCtx() {
        return this;
    }

    @Override
    protected Class<?> setCls() {
        return getClass();
    }

    @Override
    protected HandlerMain setHandlerMain() {
        return new ToastHandlerMain(getCtx(), getLogs());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivitySystemSetBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        updateCheckBoxes();

        binding.buttonBack.setOnClickListener(v -> {
            updateSystemSet();
            finish();
        });
    }

    private void updateCheckBoxes() {
        binding.checkboxVMC.setChecked(MyApp.getInstance().getDevSet().isVMC());
        binding.checkboxElectic.setChecked(MyApp.getInstance().getDevSet().isElectic());
        binding.checkboxShoppingCar.setChecked(MyApp.getInstance().getDevSet().isShoppingCar());
        binding.checkboxInvoice.setChecked(MyApp.getInstance().getDevSet().isInvoice());
        binding.checkboxDevNFCPay.setChecked(MyApp.getInstance().getDevSet().isDevNFCPay());
        binding.checkboxDevEsunPay.setChecked(MyApp.getInstance().getDevSet().isDevEsunPay());
        binding.checkboxDevTapPay.setChecked(MyApp.getInstance().getDevSet().isDevTapPay());
        binding.checkboxDevCash.setChecked(MyApp.getInstance().getDevSet().isDevCash());
        binding.checkboxDevLinePay.setChecked(MyApp.getInstance().getDevSet().isDevLinePay());

        binding.checkboxDevBillF.setChecked(MyApp.getInstance().getCashSetStructure().isBillF1000());
        binding.checkboxDevBillE.setChecked(MyApp.getInstance().getCashSetStructure().isBillE500());
        binding.checkboxDevBillD.setChecked(MyApp.getInstance().getCashSetStructure().isBillD100());

        binding.checkboxDevCoinF.setChecked(MyApp.getInstance().getCashSetStructure().isCoinF50());
        binding.checkboxDevCoinE.setChecked(MyApp.getInstance().getCashSetStructure().isCoinE10());
        binding.checkboxDevCoinD.setChecked(MyApp.getInstance().getCashSetStructure().isCoinD5());
        binding.checkboxDevCoinC.setChecked(MyApp.getInstance().getCashSetStructure().isCoinC1());
    }

    private void updateSystemSet() {
        MyApp.getInstance().getDevSet().setVMC(binding.checkboxVMC.isChecked());
        MyApp.getInstance().getDevSet().setElectic(binding.checkboxElectic.isChecked());
        MyApp.getInstance().getDevSet().setShoppingCar(binding.checkboxShoppingCar.isChecked());
        MyApp.getInstance().getDevSet().setInvoice(binding.checkboxInvoice.isChecked());
        MyApp.getInstance().getDevSet().setDevNFCPay(binding.checkboxDevNFCPay.isChecked());
        MyApp.getInstance().getDevSet().setDevEsunPay(binding.checkboxDevEsunPay.isChecked());
        MyApp.getInstance().getDevSet().setDevTapPay(binding.checkboxDevTapPay.isChecked());
        MyApp.getInstance().getDevSet().setDevCash(binding.checkboxDevCash.isChecked());
        MyApp.getInstance().getDevSet().setDevLinePay(binding.checkboxDevLinePay.isChecked());

        MyApp.getInstance().getCashSetStructure().setBillF1000(binding.checkboxDevBillF.isChecked());
        MyApp.getInstance().getCashSetStructure().setBillE500(binding.checkboxDevBillE.isChecked());
        MyApp.getInstance().getCashSetStructure().setBillD100(binding.checkboxDevBillD.isChecked());
        MyApp.getInstance().getCashSetStructure().setCoinF50(binding.checkboxDevCoinF.isChecked());
        MyApp.getInstance().getCashSetStructure().setCoinE10(binding.checkboxDevCoinE.isChecked());
        MyApp.getInstance().getCashSetStructure().setCoinD5(binding.checkboxDevCoinD.isChecked());
        MyApp.getInstance().getCashSetStructure().setCoinC1(binding.checkboxDevCoinC.isChecked());

        MyApp.saveSystemSet(getCtx());
    }
}